<script setup>
import { ref } from 'vue'
import Info from './info.vue'
// import AssignRole from './components/assignRole.vue'

import tableData from '~mock/user'

// 表单状态
const filterState = ref(true)
// 表单数据
const isExpand = ref(false)
const formData = {
  pagenum: 1,
  pagesize: 10,
  username: '',
  mobile: '',
  role_name: '',
  created_at: '',
  updated_at: '',

  created_at_temp: [], // el-date-picker组件保存是数组
  updated_at_temp: [] // el-date-picker组件保存是数组
}

// 分页
const onSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const onCurrentChange = (val) => {
  console.log(`current page: ${val}`)
}

// 公告编辑
const infoRef = ref()
const onUserInfo = (row) => {
  // console.log(row)

  infoRef.value.state = true

  if (row) {
    infoRef.value.formData.user_id = row.id
    infoRef.value.formData.username = row.uname
    // infoRef.value.formData.password =  切记密码这玩意 不用回显 不安全 =》 你去新浪微博、qq等常用网站    不传-使用旧密码也就是不改，传-更新
    infoRef.value.formData.mobile = row.mobile
    infoRef.value.formData.avatar = row.avatar
  }
}

const userState = ref('')
const userStateOption = [
  {
    value: 1,
    label: '通知'
  },
  {
    value: 0,
    label: '公告'
  }
]

// 批量选择
let ids = ref([])
const onSelectionChange = (val) => {
  ids.value = val
}
</script>
<template>
  <Box>
    <!-- 逻辑层 -->
    <Info ref="infoRef" />
    <!-- <AssignRole ref="assignRoleRef" /> -->
    <!-- 逻辑层 -->

    <!-- 筛选 -->
    <template #filter v-if="filterState">
      <el-form :inline="true" :model="formData">
        <el-form-item label="公告标题">
          <el-input placeholder="请输入公告标题" v-model="formData.username" />
        </el-form-item>
        <el-form-item label="操作人员">
          <el-input placeholder="请输入操作人员" v-model="formData.mobile" />
        </el-form-item>
        <el-form-item label="类型">
          <el-select v-model="userState" placeholder="公告状态" style="width: 120px">
            <el-option
              v-for="item in userStateOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="公告时间" v-show="isExpand">
          <el-date-picker
            v-model="formData.created_at_temp"
            type="datetimerange"
            range-separator="到"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary"> <span class="iconfont icon-sousuo"></span>搜索 </el-button>
          <el-button type="default"> 重置 </el-button>
        </el-form-item>
      </el-form>
    </template>
    <!-- 筛选 -->
    <!-- 内容 -->
    <!-- 按钮组 -->
    <el-row>
      <el-col :span="12">
        <el-button type="primary" @click="onUserInfo">
          <span class="iconfont icon-jiahao"></span>新增
        </el-button>
        <el-button type="success" @click="onUserInfo">
          <span class="iconfont icon-bianji"></span>修改
        </el-button>
        <el-button type="danger" :disabled="!ids.length">
          <span class="iconfont icon-shanchu"></span>删除
        </el-button>
      </el-col>

      <el-col :span="12" style="text-align: right">
        <el-button circle @click="filterState = !filterState">
          <span class="iconfont icon-sousuo"></span>
        </el-button>
        <el-button circle>
          <span class="iconfont icon-shuaxin"></span>
        </el-button>
      </el-col>
    </el-row>
    <!-- 按钮组 -->
    <!-- 表格 -->
    <el-table :data="tableData.data" :border="true" @selection-change="onSelectionChange">
      <el-table-column type="selection" align="center" fixed="left"></el-table-column>
      <el-table-column label="序号" prop="id" align="center" width="200"></el-table-column>
      <el-table-column label="公告标题" align="center" width="400">
        <template #default="scope">
          <span>{{ scope.row.account }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公告类型" align="center" width="200">
        <template #default="scope">
          <el-tag>{{ scope.row.nickname }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" width="200">
        <template #default="scope">
          <el-tag>{{ scope.row.nickname }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建者" prop="mobile" align="center" width="200"></el-table-column>
      <el-table-column
        label="创建于"
        prop="created_at"
        align="center"
        width="200"
      ></el-table-column>
      <el-table-column label="操作" align="center" width="120" fixed="right">
        <template #default="scoped">
          <el-button type="primary" link size="small" @click="onUserInfo(scoped.row)">
            <span class="iconfont icon-bianji"></span>修改
          </el-button>
          <el-button type="primary" link size="small" @click="onDelete">
            <span class="iconfont icon-shanchu"></span>删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格 -->
    <!-- 分页 -->
    <el-pagination
      v-model:current-page="formData.pagenum"
      v-model:page-size="formData.pagesize"
      :page-sizes="[10, 20, 30, 40]"
      :background="true"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
      @size-change="onSizeChange"
      @current-change="onCurrentChange"
    />
    <!-- 分页 -->
    <!-- 内容 -->
  </Box>
</template>
